{% extends "award_base.html" %}
{% load i18n %}
{% block head %}
<title>{% trans "蓝鲸开发框架" %}</title>
<link href="https://magicbox.bk.tencent.com/static_api/v3/assets/bootstrap-tagsinput-0.6.1/bootstrap-tagsinput.css"
    rel="stylesheet">
{{ block.super }}
{% endblock %}

<div class="bk-panel bk-demo">
    <div class="bk-panel-body p0">
        <table id="application" class="bk-table table-bordered">
            <thead>
                <tr>
                    <th>所属组织</th>
                    <th>申报奖项</th>
                    <th>奖项状态</th>
                    <th>申报⼈/团队</th>
                    <th>申报状态</th>
                    <th>申报时间</th>
                    <th>操作</th>
                </tr>
            </thead>
        </table>
    </div>
</div>

{% block extra_block %}
<script>
    //表格(DataTables)
    var language = {
        search: "{% trans '搜索：' %}",
        lengthMenu: "{% trans '每⻚显示 _MENU_ 记录' %}",
        zeroRecords: "{% trans '没找到相应的数据！' %}",
        info: "{% trans '分⻚ _PAGE_ / _PAGES_ 共 _TOTAL_ 条' %}",
        infoEmpty: "{% trans '暂⽆数据！' %}",
        infoFiltered: "{% trans '(从 _MAX_ 条数据中搜索)' %}",
        paginate: {
            first: "{% trans '⾸⻚' %}",
            last: "{% trans '尾⻚' %}",
            previous: "{% trans '上⼀⻚' %}",
            next: "{% trans '下⼀⻚' %}",
        }
    }
    var applicationTable = $('#application').DataTable({
        sProcessing: '<img alt="loadding"src="https://magicbox.bk.tencent.com/static_api/v3/components/loading1/images/loading_2_36x36.gif">',//这⾥很重要，如果你的加载中是⽂字，则直接写上⽂字即可，如果是gif的图⽚，使⽤img标签就可以加载
        pagingType: "full_numbers",
        paging: true, //隐藏分⻚
        ordering: false, //关闭排序
        info: true, //隐藏左下⻆分⻚信息
        searching: false, //关闭搜索
        pageLength: 10, //每⻚显示⼏条数据
        lengthChange: false, //不允许⽤户改变表格每⻚显示的记录数
        language: language, //汉化
        serverSide: true,
        lengthMenu: [5, 10, 25, 50, 75, 100],
        ajax: {
            url: '{{SITE_URL}}get_application_list/',
            method: "get",
            dataType: 'json',
            dataSrc: function (json) {
                json.draw = json.data.info.draw;
                json.recordsTotal = json.data.info.recordsTotal;
                json.recordsFiltered = json.data.info.recordsFiltered;
                json.data = json.data.info.data
                return json.data;
            },
        },
        columnDefs: [
            {
                targets: 0,
                data: "org_name", className: "text-center",
            },
            {
                targets: 1,
                data: "award_name", className: "text-center",
            },
            {
                targets: 2,
                data: "award_status", className: "text-center",
                render: function (data, type, row, meta) {
                    if (data === "⽣效中") {
                        return '<span class="bk-tag is-fill bk-warning">' + data + '</span>';
                    } else {
                        return '<span class="bk-tag is-fill bk-error">'
                            + data + '</span>';
                    }
                }
            },
            {
                targets: 3,
                data: "applicant_info", className: "text-center",
            },
            {
                targets: 4,
                data: "state", className: "text-center",
                render: function (data, type, row, meta) {
                    if (data === "审核中") {
                        return '<span class="bk-tag is-fill bk-gray">' + data + '</span>';
                    } else if (data === "已通过") {
                        return '<span class="bk-tag is-fill bk-primary">' + data + '</span>';
                    } else if (data === "未通过") {
                        return '<span class="bk-tag is-fill bk-error">'
                            + data + '</span>';
                    } else if (data === "未获奖") {
                        return '<span class="bk-tag is-fill bk-light-gray">' + data + '</span>';
                    } else if (data === "已获奖") {
                        return '<span class="bk-tag is-fill bk-success">' + data + '</span>';
                    } else {
                        return '<span class="bk-tag is-fill bk-success">未申报</span > ';
                    }
                }
            },
            {
                targets: 5,
                data: "apply_time", className: "text-center",
            },
            {
                targets: 6,
                data: "apply_id",
                render: function (data, type, row, meta) {
                    if (row.state === "未申报") {
                        return '<a class="bk-icon-button bk-warning bk-button-mini" type="button" onclick="displayAwardModal(' + row.award_id + ')" data-toggle="modal" data-target="#displayModal"title = "申报" >\n' + '<i class="bk-icon icon-file bk-icon"></i >\n' + '<i class="bk-text">申报</i>\n' + '</a>';
                    }
                    else if (row.state === "审核中") {
                        return '<a class="bk-icon-button bk-warning bk-button-mini" type="button" onclick="displayEditAwardModal(' + row.award_id + ',' + data + ')" data-toggle="modal" data-target="#editApplyModal" title="编辑">\n' + '<i class="bk-icon icon-file bk-icon"></i >\n' + '<i class="bk-text">编辑</i>\n' + '</a>';
                    }
                    else if (row.state === "未通过") {
                        return '<a class="bk-icon-button bk-warning bk-button-mini" type="button" onclick="displayEditAwardModal(' + row.award_id + ',' + data + ')" data-toggle="modal" data-target="#editApplyModal" title="编辑">\n' + '<i class="bk-icon icon-file bk-icon"></i >\n' + '<i class="bk-text">编辑</i>\n' + '<a class="bk-icon-button bk-warning bk-button-mini" type="button" onclick="displayAwardModal(' + row.award_id + ')" data-toggle="modal" data-target="#displayModal"title = "重新申请" >\n' + '<i class="bk-icon icon-file bk-icon"></i >\n' + '<i class="bk-text">重新申请</i>\n' + '</a>'
                    }
                    else if (row.state === "已通过") {
                        return '<a class="bk-icon-button bk-warning bk-button-mini" type="button" onclick="displayEditAwardModal(' + row.award_id + ',' + data + ')" data-toggle="modal" data-arget="#editApplyModal" title="编辑">\n' + '<i class="bk-icon icon-file bk-icon"></i >\n' + '<i class="bk-text">编辑</i>\n' + '</a>';
                    }
                    else if (row.state === "已获奖") {
                        return '<a class="bk-icon-button bk-success bk-button-mini" type="button" onclick="displayAwardApplyModal(' + row.award_id + ',' + data + ')" data-toggle="modal" datatarget="#displayEditApplyModal" title="查看">\n' + '<i class="bk-icon icon-search bk-icon"></i >\n' + '<i class="bk-text">查看</i>\n' + '</a>';
                    }
                    else if (row.state === "未获奖") {
                        return '<a class="bk-icon-button bk-success bk-button-mini" type="button" onclick="displayAwardApplyModal(' + row.award_id + ',' + data + ')" data-toggle="modal" datatarget="#displayEditApplyModal" title="查看">\n' + '<i class="bk-icon icon-search bk-icon"></i >\n' + '<i class="bk-text">查看</i>\n' + '</a>';
                    }
                    else {
                        return '<a class="bk-icon-button bk-warning bk-button-mini" type="button" onclick="displayAwardModal(' + row.award_id + ')" data-toggle="modal" data-target="#displayModal"title = "申报" >\n' + '<i class="bk-icon icon-file bk-icon"></i >\n' + '<i class="bk-text">申报</i>\n' + '</a>';
                    }
                }
            },
        ]
    });
</script>
{% endblock %}




<div class="modal fade" id="displayModal" tabindex="1" role="dialog" aria-labelledby="displayModalLabel"
    data-backdrop="static">
    <div class="modal-dialog" style="width: 1000px;">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                <h4 class="modal-title" id="displayModalLabel">申报奖项</h4>
            </div>
            <div class="row">
                <div class="col-lg-6">
                    <div class="bk-form" style="padding: 10px">
                        <input type="hidden" id="award_id" class="bk-form-input">
                        <div class="bk-form-item">
                            <label class="bk-label" style="width:150px;">奖项名称：</label>
                            <div class="bk-form-content" style="margin-left:150px;">
                                <p id="display_award_name" class="p_class"></p>
                            </div>
                        </div>
                        <div class="bk-form-item">
                            <label class="bk-label" style="width:150px;">评奖条件：</label>
                            <div class="bk-form-content" style="margin-left:150px;">
                                <p class="p_class" id="display_requirement" style="word-break: break-word"></p>
                            </div>
                        </div>
                        <div class="bk-form-item">
                            <label class="bk-label" style="width:150px;">奖项级别：</label>
                            <div class="bk-form-content" style="margin-left:150px;">
                                <p class="p_class" id="display_award_level"></p>
                            </div>
                        </div>
                        <div class="bk-form-item">
                            <label class="bk-label" style="width:150px;">所属组织：</label>
                            <div class="bk-form-content" style="margin-left:150px;">
                                <p class="p_class" id="display_belonging_org"></p>
                            </div>
                        </div>
                        <div class="bk-form-item">
                            <label class="bk-label" style="width:150px;">开始时间：</label>
                            <div class="bk-form-content" style="margin-left:150px;">
                                <p class="p_class" id="display_start_datetime" name="display_start_datetime"></p>
                            </div>
                        </div>
                        <div class="bk-form-item">
                            <label class="bk-label" style="width:150px;">结束时间：</label>
                            <div class="bk-form-content" style="margin-left:150px;">
                                <p class="p_class" id="display_end_datetime" name="display_end_datetime"></p>
                            </div>
                        </div>
                        <div class="bk-form-item">
                            <label class="bk-label" style="width:150px;">是否需要附件：</label>
                            <div class="bk-form-content" style="margin-left:150px;">
                                <p class="p_class" id="display_need_attachment"></p>
                            </div>
                        </div>
                        <div class="bk-form-item">
                            <label class="bk-label" style="width:150px;">奖项状态：</label>
                            <div class="bk-form-content" style="margin-left:150px;">
                                <p class="p_class" id="display_status"></p>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-lg-6">
                    <form id="validate_form">
                        <div class="bk-form" style="padding: 10px28px 10px 0" id="validate_form">
                            <input type="hidden" id="applicant_id" class="bk-form-input">
                            <div class="bk-form-item is-required">
                                <label class="bk-label" style="width:150px;">申报⼈/团队</label>
                                <div class="bk-form-content" style="margin-left:150px;">
                                    <input type="text" class="bk￾form-input" id="applicant_info" name="applicant_info"
                                        placeholder="请输⼊申报⼈/团 队">
                                </div>
                            </div>
                            <div class="bk-form-item is-required">
                                <label class="bk-label" style="width:150px;">事迹介绍</label>
                                <div class="bk-form-content" style="margin-left:150px;">
                                    <textarea class="bk-form-textareaignore" id="introduction" name="introduction"
                                        placeholder="请输⼊事迹介绍"></textarea>
                                </div>
                            </div>
                            <div class="bk-form-item">
                                <label class="bk-label" style="width:150px;">附件</label>
                                <div class="bk-form-content" style="margin-left:150px;">
                                    <input type="file" id="fileData">
                                    {# <div class="demo" id="kendo_upload_demo1">#}
                                    {# <div class="k-widget k-upload k-header k-upload-sync k￾upload-empty">#}
                                    {# <div class="k-button k-upload-button">#}
                                    {# <input name="files" class="file_input"type="file" data-role="upload" id="fileData"autocomplete="off"><span>选择...</span>#}
                                    {# 
 </div>#}
                                    {# 
 </div>#}
                                    {# 
 </div>#}
                                </div>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="bk-button bk-default" data-dismiss="modal">关闭</button>
                <button type="submit" id="saveOrg" onclick="applyAward()" class="bk-button bk-primary">提交</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div>
<div class="modal fade" id="editApplyModal" tabindex="1" role="dialog" aria-labelledby="editApplyModalLabel"
    data-backdrop="static">
    <div class="modal-dialog" style="width: 1000px;">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                <h4 class="modal-title" id="editApplyModalLabel">申报奖项</h4>
            </div>
            <div class="row">
                <div class="col-lg-6">
                    <div class="bk-form" style="padding: 10px">
                        <input type="hidden" id="edit_award_id" class="bk-form-input">
                        <div class="bk-form-item">
                            <label class="bk-label" style="width:150px;">奖项名称：</label>
                            <div class="bk-form-content" style="margin-left:150px;">
                                <p id="edit_display_award_name" class="p_class"></p>
                            </div>
                        </div>
                        <div class="bk-form-item">
                            <label class="bk-label" style="width:150px;">评奖条件：</label>
                            <div class="bk-form-content" style="margin-left:150px;">
                                <p class="p_class" id="edit_display_requirement" style="word-break: break-word"></p>
                            </div>
                        </div>
                        <div class="bk-form-item">
                            <label class="bk-label" style="width:150px;">奖项级别：</label>
                            <div class="bk-form-content" style="margin-left:150px;">
                                <p class="p_class" id="edit_display_award_level"></p>
                            </div>
                        </div>
                        <div class="bk-form-item">
                            <label class="bk-label" style="width:150px;">所属组织：</label>
                            <div class="bk-form-content" style="margin-left:150px;">
                                <p class="p_class" id="edit_display_belonging_org"></p>
                            </div>
                        </div>
                        <div class="bk-form-item">
                            <label class="bk-label" style="width:150px;">开始时间：</label>
                            <div class="bk-form-content" style="margin-left:150px;">
                                <p class="p_class" id="edit_display_start_datetime" name="display_start_datetime">
                                </p>
                            </div>
                        </div>
                        <div class="bk-form-item">
                            <label class="bk-label" style="width:150px;">结束时间：</label>
                            <div class="bk-form-content" style="margin-left:150px;">
                                <p class="p_class" id="edit_display_end_datetime" name="edit_display_end_datetime">
                                </p>
                            </div>
                        </div>
                        <div class="bk-form-item">
                            <label class="bk-label" style="width:150px;">是否需要附件：</label>
                            <div class="bk-form-content" style="margin-left:150px;">
                                <p class="p_class" id="edit_display_need_attachment"></p>
                            </div>
                        </div>
                        <div class="bk-form-item">
                            <label class="bk-label" style="width:150px;">奖项状态：</label>
                            <div class="bk-form-content" style="margin-left:150px;">
                                <p class="p_class" id="edit_display_status"></p>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-lg-6">
                    <form id="validate_edit_form">
                        <div class="bk-form" style="padding: 10px28px 10px 0" id="validate_edit_form">
                            <input type="hidden" id="edit_applicant_id" class="bk-form-input">
                            <div class="bk-form-item is-required">
                                <label class="bk-label" style="width:150px;">申报⼈/团队</label>
                                <div class="bk-form-content" style="margin-left:150px;">
                                    <input type="text" class="bk￾form-input" id="edit_applicant_info"
                                        name="edit_applicant_info" placeholder="请输⼊申报⼈/团 队">
                                </div>
                            </div>
                            <div class="bk-form-item is-required">
                                <label class="bk-label" style="width:150px;">事迹介绍</label>
                                <div class="bk-form-content" style="margin-left:150px;">
                                    <textarea class="bk-form-textareaignore" id="edit_introduction"
                                        name="edit_introduction" placeholder="请输⼊事迹介绍"></textarea>
                                </div>
                            </div>
                            <div class="bk-form-item">
                                <label class="bk-label" style="width:150px;">附件</label>
                                <div class="bk-form-content" style="margin-left:150px;">
                                    <a href="" target="_blank" id="edit_attachment_url"><span
                                            class="bk-tag is-fillbk-primary">点击查看附件</span></a>
                                </div>
                                <div class="bk-form-item">
                                    <label class="bk-label" style="width:150px;">重新上传附件</label>
                                    <div class="bk-form-content" style="margin-left:150px;">
                                        <input type="file" id="edit_fileData">
                                    </div>
                                </div>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="bk-button bk-default" data-dismiss="modal">关闭</button>
                <button type="submit" id="saveEditAward" onclick="saveEditAward()" class="bk-button bk-primary">提交
                </button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div>
{% block extra_block %}
<script>
    function displayAwardModal(id) {
        $.ajax({
            url: '{{ SITE_URL }}get_award_display_info/' + id,
            method: 'get',
            success: function (response) {
                if (response['result']) {

                    $("#display_award_name").html(response.data.info.data.award_name);

                    $("#display_requirement").html(response.data.info.data.requirement);

                    $("#display_award_level").html(response.data.info.data.award_level);

                    $("#display_belonging_org").html(response.data.info.data.belonging_org);

                    $("#display_start_datetime").html(response.data.info.data.start_time);

                    $("#display_end_datetime").html(response.data.info.data.end_time);

                    $("#display_need_attachment").html(response.data.info.data.need_attachment);

                    $("#display_status").html(response.data.info.data.status);
                    $("#award_id").val(response.data.info.data.id);
                } else {
                    // 失败处理
                    new bkMessage({
                        message: response['message'],
                        theme: 'error',
                        delay: 3000
                    });
                }
            }
        })
    }
    $('#validate_form').validate({
        ignore: '.ignore',
        errorElement: 'div', //错误信息的容器
        errorClass: 'is-danger',
        errorPlacement: function (error, element) {
            error.addClass('bk-form-tip').insertAfter(element)
        },
        success: function (label) { //验证通过的提示图标
            label.html('<div class="bk-badge bk-success"><i class= "bk-icon icon-check-1" ></i ></div > ');
        },
        validClass: "bk-valid",
        //验证规则
        rules: {
            introduction: {
                required: true,
            },
            applicant_info: {
                required: true,
            }
        },
        //错误提示信息
        messages: {
            applicant_info: "<p class='bk-tip-text'>申报⼈/团队为必填项！</p> ",
            introduction: "<p class='bk-tip-text'>事迹介绍为必填项！</p> ",
        }
    });
    function applyAward() {
        if ($('#validate_form').valid()) {
            var file = $('#fileData')[0].files[0];
            var introduction = $("#introduction").val();
            var applicant_info = $('#applicant_info').val();
            var award_id = $('#award_id').val();
            var applicant_id = $('#applicant_id').val();
            var formdata = new FormData();
            formdata.append('introduction', introduction);
            formdata.append('applicant_info', applicant_info);
            formdata.append('applicant_id', applicant_id);
            formdata.append('award_id', award_id);
            formdata.append('file', file);
            $.ajax({
                url: '{{ SITE_URL }}save_apply_award_info/',
                method: 'post',
                data: formdata,
                processData: false, // 不处理数据( 必须有)
                contentType: false, //不设置内容类型 ( 必须要)
                header: {
                    'X-CSRFToken': "{{ csrf_token }}",
                },
                success: function (response) {
                    if (response['result']) {
                        new bkMessage({
                            message: response['message'],
                            theme: 'success'
                        })
                        $('#displayModal').modal('hide')
                        applicationTable.ajax.reload(null, false)
                    } else {
                        // 失败处理
                        new bkMessage({
                            message: response['message'],
                            theme: 'error',
                            delay: 3000
                        });
                    }
                }
            })
        }
    }
    $('#displayModal').on('hide.bs.modal', function () {
        document.getElementById("validate_form").reset();
        $("#validate_form").validate().resetForm();
        $('#applicant_id').val("");
        $('#introduction').val("");
        $('#applicant_info').val("");
    });
    function displayEditAwardModal(award_id, apply_id) {
        $.ajax({
            url: '{{ SITE_URL }}get_edit_award_display_info/' +
                award_id + '/' + apply_id,
            method: 'get',
            success: function (response) {
                if (response['result']) {

                    $("#edit_display_award_name").html(response.data.info.data.award_name
                    );

                    $("#edit_display_requirement").html(response.data.info.data.requirement);

                    $("#edit_display_award_level").html(response.data.info.data.award_level);

                    $("#edit_display_belonging_org").html(response.data.info.data.belonging_org);

                    $("#edit_display_start_datetime").html(response.data.info.data.start_time);

                    $("#edit_display_end_datetime").html(response.data.info.data.end_time
                    );


                    $("#edit_display_need_attachment").html(response.data.info.data.need_attachment);

                    $("#edit_display_status").html(response.data.info.data.status);

                    $("#edit_award_id").val(response.data.info.data.id);

                    $("#edit_applicant_info").val(response.data.info.data.applicant_info);

                    $("#edit_introduction").val(response.data.info.data.introduction);
                    $("#edit_attachment_url").attr('href', "{{SITE_URL }}" + response.data.info.data.attachment_url);
                }
                else {
                    // 失败处理
                    new bkMessage({
                        message: response['message'],
                        theme: 'error',
                        delay: 3000
                    });
                }
            }
        })
    }
    $('#editApplyModal').on('hide.bs.modal', function () {
        document.getElementById("validate_edit_form").reset();
        $("#validate_edit_form").validate().resetForm();
        $('#edit_applicant_id').val("");
        $('#edit_introduction').val("");
        $('#edit_applicant_info').val("");
    });
    $('#validate_edit_form').validate({
        ignore: '.ignore',
        errorElement: 'div', //错误信息的容器
        errorClass: 'is-danger',
        errorPlacement: function (error, element) {
            error.addClass('bk-form-tip').insertAfter(element)
        },
        success: function (label) { //验证通过的提示图标
            label.html('<div class="bk-badge bk-success"><i class= "bk-icon icon-check-1" ></i ></div > ');
        },
        validClass: "bk-valid",
        //验证规则
        rules: {
            edit_introduction: {
                required: true,
            },
            edit_applicant_info: {
                required: true,
            }
        },
        //错误提示信息
        messages: {
            edit_applicant_info: "<p class='bk-tip-text'>申报⼈/团队为必填项！</p> ",
            edit_introduction: "<p class='bk-tip-text'>事迹介绍为必填项！</p> ",
        }
    });
    function saveEditAward() {
        if ($('#validate_edit_form').valid()) {
            var file = $('#edit_fileData')[0].files[0];
            var introduction = $("#edit_introduction").val();
            var applicant_info = $('#edit_applicant_info').val();
            var award_id = $('#edit_award_id').val();
            var applicant_id = $('#edit_applicant_id').val();
            var formdata = new FormData();
            formdata.append('introduction', introduction);
            formdata.append('applicant_info', applicant_info);
            formdata.append('applicant_id', applicant_id);
            formdata.append('award_id', award_id);
            formdata.append('file', file);
            $.ajax({
                url: '{{ SITE_URL }}save_apply_award_info/',
                method: 'post',
                data: formdata,
                processData: false, // 不处理数据( 必须有)
                contentType: false, //不设置内容类型 ( 必须要)
                header: {
                    'X-CSRFToken': "{{ csrf_token }}",
                },
                success: function (response) {
                    if (response['result']) {
                        new bkMessage({
                            message: response['message'],
                            theme: 'success'
                        })
                        $('#editApplyModal').modal('hide')
                        applicationTable.ajax.reload(null, false)
                    } else {
                        // 失败处理
                        new bkMessage({
                            message: response['message'],
                            theme: 'error',
                            delay: 3000
                        });
                    }
                }
            })
        }
    }
</script>
{% endblock %}

{% block extra_block %}
<script>
    function displayAwardApplyModal(award_id, apply_id) {
        $.ajax({
            url: '{{ SITE_URL }}get_display_award_apply_info/' +
                award_id + '/' + apply_id,
            method: 'get',
            success: function (response) {
                if (response['result']) {

                    $("#display_edit_display_award_name").html(response.data.info.data.award_name);

                    $("#display_edit_display_requirement").html(response.data.info.data.requirement);

                    $("#display_edit_display_award_level").html(response.data.info.data.award_level);

                    $("#display_edit_display_belonging_org").html(response.data.info.data.belonging_org);
                    $("#display_edit_display_start_datetime").html(response.data.info.data.start_time);

                    $("#display_edit_display_end_datetime").html(response.data.info.data.end_time);

                    $("#display_edit_display_need_attachment").html(response.data.info.data.need_attachment);

                    $("#display_edit_display_status").html(response.data.info.data.status);

                    $("#display_edit_applicant_info").html(response.data.info.data.applicant_info);

                    $("#display_edit_introduction").html(response.data.info.data.introduction);
                    $("#display_edit_attachment_url").attr('href', "{{ SITE_URL }}" + response.data.info.data.attachment_url);

                    $("#display_comment").html(response.data.info.data.comment);

                    $("#display_state").html(response.data.info.data.state);
                } else {
                    // 失败处理
                    new bkMessage({
                        message: response['message'],
                        theme: 'error',
                        delay: 3000
                    });
                }
            }
        })
    }
</script>
{% endblock %}

<div class="bk-panel bk-demo">
    <div class="bk-panel-body p0">
        <table id="application" class="bk-table table-bordered">
            <thead>
                <tr>
                    <th>所属组织</th>
                    <th>申报奖项</th>
                    <th>奖项状态</th>
                    <th>申报⼈/团队</th>
                    <th>申报状态</th>
                    <th>申报时间</th>
                    <th>操作</th>
                </tr>
            </thead>
        </table>
    </div>
</div>
{% block extra_block %}
<script src="https://magicbox.bk.tencent.com/static_api/v3/assets/bkSwitcher-1.0/js/bkSwitcher.js"></script>
<script>
    //表格(DataTables)
    var language = {
        search: "{% trans '搜索：' %}",
        lengthMenu: "{% trans '每⻚显示 _MENU_ 记录' %}",
        zeroRecords: "{% trans '没找到相应的数据！' %}",
        info: "{% trans '分⻚ _PAGE_ / _PAGES_ 共 _TOTAL_ 条' %}",
        infoEmpty: "{% trans '暂⽆数据！' %}",
        infoFiltered: "{% trans '(从 _MAX_ 条数据中搜索)' %}",
        paginate: {
            first: "{% trans '⾸⻚' %}",
            last: "{% trans '尾⻚' %}",
            previous: "{% trans '上⼀⻚' %}",
            next: "{% trans '下⼀⻚' %}",
        }
    }
    var applicationTable = $('#application').DataTable({
        sProcessing: '<img alt="loadding" src="https://magicbox.bk.tencent.com/static_api/v3/components/loading1/images/loading_2_36x36.gif">',//这⾥很重要，如果你的加载中是⽂字，则直接写上⽂字即可，如果是gif的图⽚，使⽤img标签就可以加载
        pagingType: "full_numbers",
        paging: true, //隐藏分⻚
        ordering: false, //关闭排序
        info: true, //隐藏左下⻆分⻚信息
        searching: false, //关闭搜索
        pageLength: 10, //每⻚显示⼏条数据
        lengthChange: false, //不允许⽤户改变表格每⻚显示的记录数
        language: language, //汉化
        serverSide: true,
        lengthMenu: [5, 10, 25, 50, 75, 100],
        ajax: {
            url: '{{SITE_URL}}get_review_list/',
            method: "get",
            dataType: 'json',
            dataSrc: function (json) {
                json.draw = json.data.info.draw;
                json.recordsTotal = json.data.info.recordsTotal;
                json.recordsFiltered = json.data.info.recordsFiltered;
                json.data = json.data.info.data
                return json.data;
            },
        },
        columnDefs: [
            {
                targets: 0,
                data: "org_name", className: "text-center",
            },
            {
                targets: 1,
                data: "award_name", className: "text-center",
            },
            {
                targets: 2,
                data: "award_status", className: "text-center",
                render: function (data, type, row, meta) {
                    if (data === "⽣效中") {
                        return '<span class="bk-tag is-fill bk-warning">' + data + '</span>';
                    } else {
                        return '<span class="bk-tag is-fill bk-error">' + data + '</span>';
                    }
                }
            },
            {
                targets: 3,
                data: "applicant_info", className: "text-center",
            },
            {
                targets: 4,
                data: "state", className: "text-center",
                render: function (data, type, row, meta) {
                    if (data === "审核中") {
                        return '<span class="bk-tag is-fill bk-gray">' + data + '</span>';
                    } else if (data === "已通过") {
                        return '<span class="bk-tag is-fill bk-primary">' + data + '</span>';
                    } else if (data === "未通过") {
                        return '<span class="bk-tag is-fill bk-error">' + data + '</span>';
                    } else if (data === "未获奖") {
                        return '<span class="bk-tag is-fill bk-light-gray">' + data + '</span>';
                    } else {
                        return '<span class="bk-tag is-fill bk-success">' + data + '</span>';
                    }
                }
            },
            {
                targets: 5,
                data: "apply_time", className: "text-center",
            },
            {
                targets: 6,
                data: "id",
                render: function (data, type, row, meta) {
                    if (row.state === "未申报") {
                        return '--';
                    } else if (row.state === "审核中") {
                        return '<a class="bk-icon-button bk-primary bk-button-mini" type="button" onclick="reviewApplyAward(1, ' + data + ')" title="通过">\n' + '<i class="bk-icon icon-check-1 bk-icon"></i>\n' + '<i class="bk-text">通过</i>\n' + '</a>' + '<a class="bk-icon-button bk-danger bk-button-mini" type="button" onclick="reviewApplyAward(0, ' + data + ')" title="驳回">\n' + '<i class="bk-icon icon-close bk-icon"></i>\n' + '<i class="bk-text">驳回</i>\n' + '</a>';
                    } else if (row.state === "未通过") {
                        return '--'
                    } else if (row.state === "已通过") {
                        return '<a class="bk-icon-button bk-success bk-button-mini" type="button" onclick="displayApplyAndAwardsModal(' + row.award_id + ',' + data + ')" data-toggle="modal" datatarget="#displayApplyAndAwardsModal" title="评奖">\n' + '<i class="bk-icon icon-cog bk-icon"></i>\n' + '<i class="bk-text">评奖</i>\n' + '</a>';
                    } else if (row.state === "已获奖") {
                        return '--';
                    } else {
                        return '--';
                    }
                }
            },
        ]
    });
</script>
{% endblock %}
